/***********************************************************************************
 *FileName:  nsuc16xx_spi.h
 *Version:   V1.0
 *Date:      2024-04-22
 ***********************************************************************************/

#ifndef __NSUC16XX_SPI_H__
#define __NSUC16XX_SPI_H__

/***************************************Includes***********************************/
#include "nsuc16x0.h"

/***************************************Macros*************************************/
#define SPI_CPHA_1Edge                  ((uint8_t)0x00)
#define SPI_CPHA_2Edge                  ((uint8_t)0x01)

#define SPI_CPOL_Low                    ((uint8_t)0x00)
#define SPI_CPOL_High                   ((uint8_t)0x01)

#define SPI_DataSize_8b                 ((uint8_t)0x00)
#define SPI_DataSize_16b                ((uint8_t)0x01)
#define SPI_DataSize_24b                ((uint8_t)0x02)
#define SPI_DataSize_32b                ((uint8_t)0x03)

#define SPI_FirstBit_MSB                ((uint8_t)0x00)
#define SPI_FirstBit_LSB                ((uint8_t)0x01)

#define SPI_WMode_4Wire                 ((uint8_t)0x00)
#define SPI_WMode_3Wire                 ((uint8_t)0x01)

#define SPI_Direction_TX                ((uint8_t)0x00)
#define SPI_Direction_RX                ((uint8_t)0x01)

#define SPI_BaudRatePrescaler_2         ((uint8_t)0x00)
#define SPI_BaudRatePrescaler_4         ((uint8_t)0x01)
#define SPI_BaudRatePrescaler_8         ((uint8_t)0x02)
#define SPI_BaudRatePrescaler_16        ((uint8_t)0x03)
#define SPI_BaudRatePrescaler_32        ((uint8_t)0x04)
#define SPI_BaudRatePrescaler_64        ((uint8_t)0x05)
#define SPI_BaudRatePrescaler_128       ((uint8_t)0x06)
#define SPI_BaudRatePrescaler_256       ((uint8_t)0x07)
#define SPI_BaudRatePrescaler_512       ((uint8_t)0x08)

#define SPI_FLAG_BUSY                   ((uint32_t)0x00000001)
#define SPI_FLAG_TXFE                   ((uint32_t)0x00000010)
#define SPI_FLAG_TXFF                   ((uint32_t)0x00000020)
#define SPI_FLAG_TXFC                   ((uint32_t)0x00000040)
#define SPI_FLAG_TXFO                   ((uint32_t)0x00000080)
#define SPI_FLAG_RXFE                   ((uint32_t)0x00001000)
#define SPI_FLAG_RXFF                   ((uint32_t)0x00002000)
#define SPI_FLAG_RXFC                   ((uint32_t)0x00004000)
#define SPI_FLAG_RXFO                   ((uint32_t)0x00008000)




/***************************************Variables**********************************/
typedef struct
{
    uint8_t SPI_CPHA; 
    uint8_t SPI_CPOL; 
    uint8_t SPI_FirstBit; 
    uint8_t SPI_DataSize; 
    uint8_t SPI_WMode;
    uint8_t SPI_Direction; 
    uint8_t SPI_BaudRatePrescaler;
    uint8_t SPI_TXFIFOThreshold;
    uint8_t SPI_RXFIFOThreshold;
} SPI_InitTypeDef;

/***************************************Functions**********************************/
void SPI_Init(SPI_TypeDef *SPIx, SPI_InitTypeDef *SPI_InitStruct);
void SPI_Cmd(SPI_TypeDef *SPIx, FunctionalState NewState);
void SPI_SetTransceiverMode(SPI_TypeDef *SPIx, uint8_t Mode);
void SPI_SendData(SPI_TypeDef *SPIx, uint32_t Data);
uint32_t SPI_ReceiveData(SPI_TypeDef *SPIx);
FlagStatus SPI_GetFlagStatus(SPI_TypeDef *SPIx, uint32_t SPI_FLAG);

#endif
/* [] END OF nsuc16xx_spi.h */
